﻿<UserControl x:Class="InfFront.InfoViews.WPF.MenuTabsFrame"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:InfFront.InfoViews.WPF"
    xmlns:viewbase="clr-namespace:InfFront.InfoViews.Base;assembly=InfFront.InfoViews.Base"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    Height="Auto" Width="Auto" MinWidth="600" MinHeight="400">
        
    <UserControl.Resources>
        <local:IconedObjectToNormal16x16ImageConverter x:Key="getNormal16x16Image"/>
        <local:IconedObjectToNormal24x24ImageConverter x:Key="getNormal24x24Image"/>
        <local:BoolNotConverter x:Key="BoolNot" />        
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Menu Name="mnuSources" Grid.Row="0">
            <Menu.Background>
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
                    <GradientStop Offset="0" Color="{Binding Path=VisualSettings.SecondaryBackgroundColor, FallbackValue=Azure}"/>
                    <GradientStop Offset="1" Color="{Binding Path=VisualSettings.PrimaryBackgroundColor, FallbackValue=Lavender}"/>
                </LinearGradientBrush>
            </Menu.Background>
            <Menu.ItemContainerStyle>
                <Style TargetType="{x:Type MenuItem}">
                    <EventSetter Event="Click" Handler="menuItem_Click" />
                    <EventSetter Event="MouseEnter" Handler="menuItem_MouseEnter"/>
                    <EventSetter Event="PreviewMouseLeftButtonDown" Handler="menuItem_PreviewMouseLeftButtonDown"/>
                    <Style.Triggers> 
                        <Trigger Property="IsMouseDirectlyOver" Value="true"> <!-- this dont work :( -->
                            <Setter Property="IsSubmenuOpen" Value="true"/>
                        </Trigger>
                        <Trigger Property="IsMouseDirectlyOver" Value="false"> <!-- this dont work :( -->
                            <Setter Property="IsSubmenuOpen" Value="false"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Menu.ItemContainerStyle>
            <Menu.ItemTemplate>
                <HierarchicalDataTemplate DataType = "{x:Type viewbase:InfoViewSource}"
                                              ItemsSource = "{Binding Path=NestedSources}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
                            <ColumnDefinition Width="*" SharedSizeGroup="Title" />
                        </Grid.ColumnDefinitions>
                        <Image  Margin="4,0,2,0" VerticalAlignment="Center" Grid.Column="0"
                                Source="{Binding Converter={StaticResource getNormal16x16Image}}" Width="16" Height="16" />
                        <TextBlock Grid.Column="1" Text="{Binding Path=Title}" 
                                   Margin="0,0,6,0" VerticalAlignment="Center"/>
                    </Grid>
                </HierarchicalDataTemplate>
            </Menu.ItemTemplate>
        </Menu>

        <TabControl Name="tabs" Grid.Row="1" Width="Auto" Height="Auto" Background="Transparent">
            <TabControl.ItemContainerStyle>
                <Style TargetType="{x:Type TabItem}">
                    <!--<Setter Property="Header" Value="{Binding Path=Title}" />-->
                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <local:SourceFrame DataContext="{Binding}" Width="Auto" Height="Auto" />
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                    <!--<Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type TabItem}">
                                <Border Name="Border" >
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>
                                        <ContentPresenter Name="Icon" Margin="4,2,2,2" ContentTemplate="{StaticResource iconDataTemplate}"
                                      VerticalAlignment="Center" ContentSource="Icon"/>
                                        <ContentPresenter Name="HeaderHost" Grid.Column="1" ContentSource="Header"
                                      RecognizesAccessKey="True" Margin="0,0,6,0" VerticalAlignment="Center" />
                                    </Grid>
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="Icon" Value="{x:Null}">
                                        <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
                                    </Trigger>
                                    <Trigger Property="IsHighlighted" Value="true">
                                        <Setter TargetName="Border" Property="Background">
                                            <Setter.Value>
                                                <SolidColorBrush Color ="{Binding Path=VisualSettings.PrimaryBackgroundColor, FallbackValue=Lavender}" />
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>-->
                </Style>
            </TabControl.ItemContainerStyle>
            <TabControl.ItemTemplate>
                <DataTemplate DataType = "{x:Type viewbase:InfoViewSource}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
                            <ColumnDefinition Width="*" SharedSizeGroup="Title" />
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Image  VerticalAlignment="Center" Grid.Column="0"
                                Source="{Binding Converter={StaticResource getNormal24x24Image}}" Width="24" Height="24" />
                        <TextBlock Grid.Column="1" Text="{Binding Path=Title}" 
                                   Margin="4,0,20,0" VerticalAlignment="Center"/>
                        <Button Focusable="False" VerticalAlignment="Center" Grid.Column="2" IsTabStop="False" Background="Transparent" ClickMode="Press"
                                Click="tabCloseButton_Click" Width="18" Height="18">
                            <Image Source="/InfFront.InfoViews.WPF;component/Resources/cross14.bmp" />
                        </Button>
                    </Grid>
                </DataTemplate>
            </TabControl.ItemTemplate>
        </TabControl>
    </Grid>
</UserControl>
